<?php
/**
 * @Author: anchen
 * @Date:   2017-04-20 21:42:10
 * @Last Modified by:   anchen
 * @Last Modified time: 2017-04-20 22:11:34
 */
/**
 * base64、MD5加密解密
 * @param  string 加密解密的类型 比如：密码
 * @param  string 加密解密的内容
 * @param  int 0-加密 1-解密
 * return string
 */
function encryptDecrypt($key,$string,$decrypt){
    if($decrypt == 1){
        echo 1;
        $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256,md5($key),base64_decode($string),MCRYPT_MODE_CBC,md5(md5($key))),"12");
        return $decrypted;
    }elseif($decrypt == 0){
        echo 2;
        $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256,md5($key),$string,MCRYPT_MODE_CBC,md5(md5($key))));
        return $encrypted;
    }
}
echo encryptDecrypt('password','123456',0);
